package com.AAL.DAO;

import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.classic.Session;

import com.AAL.DAO.Interface.ISpeedDAO;
import com.AAL.Model.Speed;
import com.AAL.Model.StatusOfAccount;
import com.AAL.Utils.HibernateUtil;

public class SpeedDAO implements ISpeedDAO{

	@Override
	public Speed getSpeed(int speedID) {		
		System.out.println("getSpeed");
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		Speed speed = (Speed) session.load(Speed.class,(short) speedID);
		System.out.println("getSpeed"+speed.getSpeedSymbol());
		return speed;
		
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Speed> getAllSpeeds() {
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		List<Speed> lstSpeeds = null;
		try {
			lstSpeeds = (List<Speed>) session.createQuery("from Speed").list();
		} catch (HibernateException e) {
			e.printStackTrace();
			session.getTransaction().rollback();
		}
		session.getTransaction().commit();
		return lstSpeeds;
	}

}
